package com.fyd.mybatis.test;

import com.fyd.mybatis.binding.MapperRegistry;
import com.fyd.mybatis.session.SqlSession;
import com.fyd.mybatis.session.SqlSessionFactory;
import com.fyd.mybatis.session.defaults.DefaultSqlSessionFactory;
import com.fyd.mybatis.test.dao.IUserDao;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description
 * @Auther: fyd20
 * @Date: 2025/6/4 13:40
 * @Description: ApiTest
 * @Version 1.0.0
 */
public class ApiTest {

    private Logger logger = LoggerFactory.getLogger(ApiTest.class);

    @Test
    public void test_mapperProxyRegister(){
        //1. 注册
        MapperRegistry mapperRegistry = new MapperRegistry();
        mapperRegistry.addMappers("com.fyd.mybatis.test.dao");

        //2. 从sqlSession 工厂获取 Session
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(mapperRegistry);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        // 3.获取映射器对象
        IUserDao userDao = sqlSession.getMapper(IUserDao.class);

        // 4.测试验证
        String res = userDao.queryUserName("10001");

        logger.info("测试结果：{}",res);

    }
}
